// pages/todolist/todolist.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        value: "",
        list: [{
            staus: false,
            title: "待办事项"
        }]
    },
    dianji() {
        console.log(this.data.value);
        if (this.data.value != "" && !this.data.list.some(item => item.title == this.data.value)) {
            this.data.list.push({
                staus: false,
                title: this.data.value
            })

        }

        // wx:setstorageSync('todist',this.data.list)
        wx.setStorage({
                data: this.data.list,
                key: 'todolist',
            }),
            this.setData({
                list: this.data.list
            })
        console.log(this.data.list);

    },
    delet(e) {
        console.log(e);
        // e.currentTarget.dataset.item
        this.data.list = this.data.list.filter(item => item.title != e.currentTarget.dataset.item.title)
        wx.setStorage({
                data: this.data.list,
                key: 'todolist',
            })
            this.setData({
                list: this.data.list
            })
    },
    check(e) {
        console.log(e);

        // this.data.list[e.currentTarget.dataset.staus].
        const index = e.currentTarget.dataset.index
        this.data.list[index].staus = this.data.list[index].staus == "true" ? "false" : "true"

        wx.setStorage({
            data: this.data.list,
            key: 'todolist',
        })
        this.setData({
            list: this.data.list
        })
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.data.list = wx.getStorageSync('todolist') || [],
            this.setData({
                list: this.data.list
            })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },
    onShareAppMessage: function () {
        return {
            title: "橘雎",
            imageUrl: "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1689053532,4230915864&fm=26&gp=0.jpg",
        }
    },

})